home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / pcmagwin.zip / MEMCLEAR.BAS < prev    next >
BASIC Source File  |  1992-06-06  |  2KB  |  85 lines

  1. 'MEMCLEAR.BAS - shows how to initialize variables to any value
  2. 'Copyright (c) 1992 Ethan Winer
  3.  
  4. DEFINT A-Z
  5. DECLARE SUB MemClear (Segment, Address, Size, Value)
  6.  
  7. TYPE Test
  8.   I AS INTEGER
  9.   L AS LONG
  10.   S AS SINGLE
  11.   D AS DOUBLE
  12. END TYPE
  13.  
  14. DIM TestType AS Test            'create a test TYPE variable
  15. TestType.I = 123                'and assign some values
  16. TestType.L = -123456
  17. TestType.S = 123.456
  18. TestType.D = -123.456
  19.  
  20. REDIM A&(1 TO 150)              'create a test array
  21. FOR X = 1 TO 150                'and assign some values
  22.   A&(X) = X
  23. NEXT
  24.  
  25. S$ = SPACE$(200)                'create a test string
  26. FOR X = 1 TO 200                'and assign some values
  27.   MID$(S$, X, 1) = CHR$(X + 35)
  28. NEXT
  29.  
  30. GOSUB Display                   'show the current contents
  31. PRINT
  32. PRINT "Press a key to clear the variables"
  33. WHILE INKEY$ = "": WEND
  34.  
  35. 'set the TYPE and array elements to all zeros, and the string to "A"'s
  36. CALL MemClear(VARSEG(TestType), VARPTR(TestType), LEN(TestType), 0)
  37. CALL MemClear(VARSEG(A&(1)), VARPTR(A&(1)), 200 * LEN(A&(1)), 0)
  38. CALL MemClear(SSEG(S$), SADD(S$), LEN(S$), 65)
  39. '             ^^^^
  40. '               |------------ use VARSEG here instead of SSEG with QuickBASIC
  41.  
  42. GOSUB Display
  43. END
  44.  
  45. Display:
  46.   CLS
  47.   PRINT "TestType elements:"
  48.   PRINT "TestType.I :"; TestType.I
  49.   PRINT "TestType.L :"; TestType.L
  50.   PRINT "TestType.S :"; TestType.S
  51.   PRINT "TestType.D :"; TestType.D
  52.   PRINT
  53.  
  54.   PRINT "A&() elements:"
  55.   FOR X = 1 TO 150
  56.     PRINT A&(X);
  57.   NEXT
  58.  
  59.   LOCATE 18, 1
  60.   PRINT "S$ contents:"; S$
  61. RETURN
  62.  
  63. ClearCode:
  64.   DATA &H55, &H8B, &HEC, 6, &HC4, &H7E, &HA, &H8B, &H4E, 8
  65.   DATA &H8B, &H46, 6, &HF3, &HAA, 7, &H5D, &HCA, 8, 0
  66.  
  67. SUB MemClear (Segment, Address, Size, Value) STATIC
  68.  
  69.   IF NOT BeenHere THEN          'do this only once
  70.     DIM Code AS STRING * 20
  71.     RESTORE ClearCode
  72.     FOR X = 1 TO 20
  73.       READ Byte
  74.       MID$(Code$, X, 1) = CHR$(Byte)
  75.     NEXT
  76.     Proc = VARPTR(Code$)
  77.     BeenHere = -1
  78.   END IF
  79.  
  80.   DEF SEG
  81.   CALL Absolute(BYVAL Segment, BYVAL Address, BYVAL Size, BYVAL Value, Proc)
  82.  
  83. END SUB
  84.  
  85.